﻿using System;
using System.IO;
using System.Net;
using System.Net.Sockets;

namespace zmMoniter
{

    /// <summary>
    /// 表示客户端信息的类
    /// </summary>
    public class ClientInfo
    {

        #region -- 私有变量 --

        private DateTime connectedTime;
        private Int32 receivedMsgCount;
        private Int32 receivedByteCount;
        private Int32 sendedMsgCount;
        private Int32 sendedByteCount;
        private Guid clientId;
        private TcpClient client;
        private MemoryStream memory;

        private DateTime lastCheckTime;

        #endregion

        #region -- 属性 --

        /// <summary>
        /// 客户端连接时间
        /// </summary>
        public DateTime ConnectedTime
        {
            get { return connectedTime; }
            set { connectedTime = value; }
        }

        /// <summary>
        /// 客户端接收的消息数
        /// </summary>
        public Int32 ReceivedMsgCount
        {
            get { return receivedMsgCount; }
            set { receivedMsgCount = value; }
        }

        /// <summary>
        /// 客户端接收的字节数
        /// </summary>
        public Int32 ReceivedByteCount
        {
            get { return receivedByteCount; }
            set { receivedByteCount = value; }
        }

        /// <summary>
        /// 向客户端发送的消息数
        /// </summary>
        public Int32 SendedMsgCount
        {
            get { return sendedMsgCount; }
            set { sendedMsgCount = value; }
        }

        /// <summary>
        /// 向客户端发送的字节数
        /// </summary>
        public Int32 SendedByteCount
        {
            get { return sendedByteCount; }
            set { sendedByteCount = value; }
        }

        /// <summary>
        /// 客户端索引
        /// </summary>
        public Guid ClientId
        {
            get { return clientId; }
            set { clientId = value; }
        }

        /// <summary>
        /// 客户端
        /// </summary>
        public TcpClient Client
        {
            get { return client; }
            set { client = value; }
        }

        /// <summary>
        /// 消息缓存流
        /// </summary>
        public MemoryStream Memory
        {
            get { return memory; }
            set { memory = value; }
        }

        #endregion

        public DateTime LastCheckTime
        {
            get { return lastCheckTime; }
            set { lastCheckTime = value; }
        }

        #region -- 方法 --

        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="clientIPEndPoint"></param>
        public ClientInfo(TcpClient client)
        {
            this.connectedTime = DateTime.Now;
            this.receivedMsgCount = 0;
            this.receivedByteCount = 0;
            this.sendedMsgCount = 0;
            this.sendedByteCount = 0;
            this.clientId = Guid.NewGuid();
            this.client = client;
            memory = new MemoryStream();
        }

        #endregion
    }
}
